package com.example.demo.MyStack.string;

import java.util.Stack;

public class zip {
    public static void main(String[] args) {
        String chars = "ssaasdadsssaaasddaass";
        StringBuffer sb = new StringBuffer();
        Stack stack = new Stack();
        String[] strings = chars.split("");
        int i = 0;
        for (; i <= strings.length - 1; i++) {
            if (stack.empty() || stack.peek().toString().equals(strings[i])) {
                stack.push(strings[i]);
            } else {
                sb.append(stack.peek());
                if (stack.size() > 1) {
                    sb.append(stack.size());
                }
                stack.clear();
                stack.push(strings[i]);
            }
            if (i == strings.length - 1) {
                sb.append(stack.peek());
                if (stack.size() > 1) {
                    sb.append(stack.size());
                }
                stack.clear();
            }
        }
        System.out.println(sb.toString());
    }
}
